home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / glibc-1.09 / glibc-1 / glibc-1.09.1 / hurd / hurd.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-06  |  10.5 KB  |  292 lines

  1. /* Copyright (C) 1993, 1994 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3.  
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. License, or (at your option) any later version.
  8.  
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. Library General Public License for more details.
  13.  
  14. You should have received a copy of the GNU Library General Public
  15. License along with the GNU C Library; see the file COPYING.LIB.  If
  16. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  17. Cambridge, MA 02139, USA.  */
  18.  
  19. #ifndef    _HURD_H
  20.  
  21. #define    _HURD_H    1
  22. #include <features.h>
  23.  
  24.  
  25. /* Get types, macros, constants and function declarations
  26.    for all Mach microkernel interaction.  */
  27. #include <mach.h>
  28. #include <mach/mig_errors.h>
  29.  
  30. /* Get types and constants necessary for Hurd interfaces.  */
  31. #include <hurd/hurd_types.h>
  32.  
  33. /* Get MiG stub declarations for commonly used Hurd interfaces.  */
  34. #include <hurd/auth.h>
  35. #include <hurd/process.h>
  36. #include <hurd/fs.h>
  37. #include <hurd/io.h>
  38.  
  39. /* Get `struct hurd_port' and related definitions implementing lightweight
  40.    user references for ports.  These are used pervasively throughout the C
  41.    library; this is here to avoid putting it in nearly every source file.  */
  42. #include <hurd/port.h>
  43.  
  44. #include <errno.h>
  45. #define    __hurd_fail(err)    (errno = (err), -1)
  46.  
  47. /* Basic ports and info, initialized by startup.  */
  48.  
  49. extern struct hurd_port *_hurd_ports;
  50. extern unsigned int _hurd_nports;
  51. extern volatile mode_t _hurd_umask;
  52.  
  53. /* Shorthand macro for referencing _hurd_ports (see <hurd/port.h>).  */
  54.  
  55. #define    __USEPORT(which, expr) \
  56.   HURD_PORT_USE (&_hurd_ports[INIT_PORT_##which], (expr))
  57.  
  58.  
  59. /* Base address and size of the initial stack set up by the exec server.
  60.    If using cthreads, this stack is deallocated in startup.
  61.    Not locked.  */
  62.  
  63. extern vm_address_t _hurd_stack_base;
  64. extern vm_size_t _hurd_stack_size;
  65.  
  66. /* Initial file descriptor table we were passed at startup.  If we are
  67.    using a real dtable, these are turned into that and then cleared at
  68.    startup.  If not, these are never changed after startup.  Not locked.  */
  69.  
  70. extern mach_port_t *_hurd_init_dtable;
  71. extern mach_msg_type_number_t _hurd_init_dtablesize;
  72.  
  73. /* Current process IDs.  */
  74.  
  75. extern pid_t _hurd_pid, _hurd_ppid, _hurd_pgrp;
  76. extern int _hurd_orphaned;
  77.  
  78. /* This variable is incremented every time the process IDs change.  */
  79.  
  80. unsigned int _hurd_pids_changed_stamp;
  81.  
  82. /* This condition is broadcast every time the process IDs change.  */
  83. struct condition _hurd_pids_changed_sync;
  84.  
  85. /* Unix `data break', for brk and sbrk.
  86.    If brk and sbrk are not used, this info will not be initialized or used.  */
  87.  
  88.  
  89. /* Data break.  This is what `sbrk (0)' returns.  */
  90.  
  91. extern vm_address_t _hurd_brk;
  92.  
  93. /* End of allocated space.  This is generally `round_page (_hurd_brk)'.  */
  94.  
  95. extern vm_address_t _hurd_data_end;
  96.  
  97. /* This mutex locks _hurd_brk and _hurd_data_end.  */
  98.  
  99. extern struct mutex _hurd_brk_lock;
  100.  
  101. /* Set the data break to NEWBRK; _hurd_brk_lock must
  102.    be held, and is released on return.  */
  103.  
  104. extern int _hurd_set_brk (vm_address_t newbrk);
  105.  
  106. #define __need_FILE
  107. #include <stdio.h>
  108.  
  109. /* Calls to get and set basic ports.  */
  110.  
  111. extern error_t _hurd_ports_get (int which, mach_port_t *result);
  112. extern error_t _hurd_ports_set (int which, mach_port_t newport);
  113.  
  114. extern process_t getproc (void);
  115. extern file_t getcwdir (void), getcrdir (void);
  116. extern auth_t getauth (void);
  117. extern mach_port_t getcttyid ();
  118. extern int setproc (process_t);
  119. extern int setcwdir (file_t), setcrdir (file_t);
  120. extern int setcttyid (mach_port_t);
  121.  
  122. /* Does reauth with the proc server and fd io servers.  */
  123. extern int __setauth (auth_t), setauth (auth_t);
  124.  
  125.  
  126. /* Split FILE into a directory and a name within the directory.  Look up a
  127.    port for the directory and store it in *DIR; store in *NAME a pointer
  128.    into FILE where the name within directory begins.  The directory lookup
  129.    uses CRDIR for the root directory and CWDIR for the current directory.
  130.    Returns zero on success or an error code.  */
  131.  
  132. extern error_t __hurd_file_name_split (file_t crdir, file_t cwdir,
  133.                        const char *file,
  134.                        file_t *dir, char **name);
  135. extern error_t hurd_file_name_split (file_t crdir, file_t cwdir,
  136.                      const char *file,
  137.                      file_t *dir, char **name);
  138.  
  139. /* Open a port to FILE with the given FLAGS and MODE (see <fcntl.h>).
  140.    The file lookup uses CRDIR for the root directory and CWDIR for the
  141.    current directory.  If successful, returns zero and store the port
  142.    to FILE in *PORT; otherwise returns an error code. */
  143.  
  144. extern error_t __hurd_file_name_lookup (file_t crdir, file_t cwdir,
  145.                     const char *file,
  146.                     int flags, mode_t mode,
  147.                     file_t *port);
  148. extern error_t hurd_file_name_lookup (file_t crdir, file_t cwdir,
  149.                       const char *filename,
  150.                       int flags, mode_t mode,
  151.                       file_t *port);
  152.  
  153. /* Process the values returned by `dir_lookup' et al, and loop doing
  154.    `dir_lookup' calls until one returns FS_RETRY_NONE.  CRDIR is the
  155.    root directory used for things like symlinks to absolute file names; the
  156.    other arguments should be those just passed to and/or returned from
  157.    `dir_lookup', `fsys_getroot', or `file_invoke_translator'.  This
  158.    function consumes the reference in *RESULT even if it returns an error.  */
  159.  
  160. extern error_t __hurd_file_name_lookup_retry (file_t crdir,
  161.                           enum retry_type doretry,
  162.                           char retryname[1024],
  163.                           int flags, mode_t mode,
  164.                           file_t *result);
  165. extern error_t hurd_file_name_lookup_retry (file_t crdir,
  166.                         enum retry_type doretry,
  167.                         char retryname[1024],
  168.                         int flags, mode_t mode,
  169.                         file_t *result);
  170.  
  171.  
  172. /* Split FILE into a directory and a name within the directory.  The
  173.    directory lookup uses the current root and working directory.  If
  174.    successful, stores in *NAME a pointer into FILE where the name
  175.    within directory begins and returns a port to the directory;
  176.    otherwise sets `errno' and returns MACH_PORT_NULL.  */
  177.  
  178. extern file_t __file_name_split (const char *file, char **name);
  179. extern file_t file_name_split (const char *file, char **name);
  180.  
  181. /* Open a port to FILE with the given FLAGS and MODE (see <fcntl.h>).
  182.    The file lookup uses the current root and working directory.
  183.    Returns a port to the file if successful; otherwise sets `errno'
  184.    and returns MACH_PORT_NULL.  */
  185.  
  186. extern file_t __file_name_lookup (const char *file, int flags, mode_t mode);
  187. extern file_t file_name_lookup (const char *file, int flags, mode_t mode);
  188.  
  189. /* Invoke any translator set on the node FILE represents, and return in
  190.    *TRANSLATED a port to the translated node.  FLAGS are as for
  191.    `dir_lookup' et al, but the returned port will not necessarily have
  192.    any more access rights than FILE does.  */
  193.  
  194. extern error_t __hurd_invoke_translator (file_t file, int flags,
  195.                      file_t *translated);
  196. extern error_t hurd_invoke_translator (file_t file, int flags,
  197.                        file_t *translated);
  198.  
  199.  
  200. /* Open a file descriptor on a port.  FLAGS are as for `open'; flags
  201.    affected by io_set_openmodes are not changed by this.  If successful,
  202.    this consumes a user reference for PORT (which will be deallocated on
  203.    close).  */
  204.  
  205. extern int openport (io_t port, int flags);
  206.  
  207. /* Open a stream on a port.  MODE is as for `fopen'.
  208.    If successful, this consumes a user reference for PORT
  209.    (which will be deallocated on fclose).  */
  210.  
  211. extern FILE *fopenport (io_t port, const char *mode);
  212. extern FILE *__fopenport (io_t port, const char *mode);
  213.  
  214.  
  215. /* Execute a file, replacing TASK's current program image.  */
  216.  
  217. extern error_t _hurd_exec (task_t task,
  218.                file_t file,
  219.                char *const argv[],
  220.                char *const envp[]);
  221.  
  222.  
  223. /* Inform the proc server we have exitted with STATUS, and kill the
  224.    task thoroughly.  This function never returns, no matter what.  */
  225.  
  226. extern void _hurd_exit (int status) __attribute__ ((noreturn));
  227.  
  228.  
  229. /* Initialize the library data structures from the
  230.    ints and ports passed to us by the exec server.
  231.    Then vm_deallocate PORTARRAY and INTARRAY.  */
  232.  
  233. extern void _hurd_init (int flags, char **argv,
  234.             mach_port_t *portarray, size_t portarraysize,
  235.             int *intarray, size_t intarraysize);
  236.  
  237. /* Do startup handshaking with the proc server.  */
  238.  
  239. extern void _hurd_proc_init (char **argv);
  240.  
  241.  
  242. /* Return the socket server for sockaddr domain DOMAIN.  If DEAD is
  243.    nonzero, remove the old cached port and always do a fresh lookup.
  244.  
  245.    It is assumed that a socket server will stay alive during a complex socket
  246.    operation involving several RPCs.  But a socket server may die during
  247.    long idle periods between socket operations.  Callers should first pass
  248.    zero for DEAD; if the first socket RPC tried on the returned port fails
  249.    with MACH_SEND_INVALID_DEST or MIG_SERVER_DIED (indicating the server
  250.    went away), the caller should call _hurd_socket_server again with DEAD
  251.    nonzero and retry the RPC on the new socket server port.  */
  252.  
  253. extern socket_t _hurd_socket_server (int domain, int dead);
  254.  
  255. /* Send a `sig_post' RPC to process number PID.  If PID is zero,
  256.    send the message to all processes in the current process's process group.
  257.    If PID is < -1, send SIG to all processes in process group - PID.
  258.    SIG and REFPORT are passed along in the request message.  */
  259.  
  260. extern error_t _hurd_sig_post (pid_t pid, int sig, mach_port_t refport);
  261. extern error_t hurd_sig_post (pid_t pid, int sig, mach_port_t refport);
  262.  
  263. /* Fetch the host privileged port and device master port from the proc
  264.    server.  They are fetched only once and then cached in the
  265.    variables below.  A special program that gets them from somewhere
  266.    other than the proc server (such as a bootstrap filesystem) can set
  267.    these variables to install the ports.  */
  268.  
  269. extern kern_return_t get_privileged_ports (host_priv_t *host_priv_ptr,
  270.                        device_t *device_master_ptr);
  271. extern mach_port_t _hurd_host_priv, _hurd_device_master;
  272.  
  273. /* Return the PID of the task whose control port is TASK.
  274.    On error, sets `errno' and returns -1.  */
  275.  
  276. extern pid_t __task2pid (task_t task), task2pid (task_t task);
  277.  
  278. /* Return the task control port of process PID.
  279.    On error, sets `errno' and returns MACH_PORT_NULL.  */
  280.  
  281. extern task_t __pid2task (pid_t pid), pid2task (pid_t pid);
  282.  
  283.  
  284. /* Return the io server port for file descriptor FD.
  285.    This adds a Mach user reference to the returned port.
  286.    On error, sets `errno' and returns MACH_PORT_NULL.  */
  287.  
  288. extern io_t __getdport (int fd), getdport (int fd);
  289.  
  290.  
  291. #endif    /* hurd.h */
  292.